class FindSumPairs:
    def __init__(self, nums1: list, nums2: list):
        self.nums1 = nums1
        self.nums2 = nums2
        self.numMap = {}
        for i in range(len(nums2)):
            num = nums2[i]
            if num not in self.numMap:
                self.numMap[num] = 0
            self.numMap[num] += 1

    def add(self, index: int, val: int) -> None:
        num = self.nums2[index]
        newNum = num + val
        self.nums2[index] = newNum
        self.numMap[num] -= 1
        if self.numMap[num] == 0:
            del self.numMap[num]
        if newNum not in self.numMap:
            self.numMap[newNum] = 0
        self.numMap[newNum] += 1

    def count(self, tot: int) -> int:
        res = 0
        for i in range(len(self.nums1)):
            diff = tot - self.nums1[i]
            res += self.numMap[diff] if diff in self.numMap else 0

        return res


if __name__ == '__main__':
    findSumPairs = FindSumPairs([1, 1, 2, 2, 2, 3], [1, 4, 5, 2, 5, 4])
    findSumPairs.add(3, 2)
    findSumPairs.add(0, 1)
    findSumPairs.add(1, 1)
    print(findSumPairs.count(7))
